<script>
var uploader_post_params={file_group_id: '{{fields.file_group_id}}',file_type_id: '{{fields.file_type_id}}',target: '{{fields.target}}',ajaj:1,sid:'{{req.cookie.sid}}',mode: 'upload',downscale:1,max_x:"{{autoscale.x}}",max_y: "{{autoscale.y}}"};
{{if fields.all}}uploader_post_params.all=1;{{/if}}
</script>
<table border="0" class="admin-filebrowser" width="100%">
<tr><td class="left-panel">
	<h1>{{!title}}</h1>
	<div class="file-groups">
	{{foreach fg in file_groups}}
		{{if fg.toomany}}<div style="margin-left: {{MUL1(20):fg.level}}px;">...</div>{{/if}}
		{{unless fg.toomany}}<a class="file-group{{if fg.active}} file-group-A{{/if}}" style="margin-left: {{MUL1(20):fg.level}}px;" href="{{action}}?{{copy_fields("all,file_type_id,target")}}file_group_id={{fg.id}}">{{fg.name}}</a>{{/unless}}
	{{/foreach}}
	</div>
</td>
<td class="right-panel">
	<div class="actions">
		<div class="action-group">{{!action_files}}</div>
		{{if fields.file_group_id}}
		<div class="action upload-many" onclick="$('.upload-many-block').toggle();">{{!action_files_upload_many}}</div>
		<div class="action upload-one" onclick="$('.upload-one-block').toggle();">{{!action_files_upload_one}}</div>
		{{/if}}
		{{unless fields.file_group_id}}<div class="action">{{!action_must_be_in_folder}}</div>{{/unless}}
		<div class="action-group">{{!action_folders}}</div>
		<div class="action file-group-new" onclick="filemanager_file_group_edit({parent_id: '{{fields.file_group_id}}'},folders_tree,{file_type_id:'{{fields.file_type_id}}',file_group_id:'{{fields.file_group_id}}',target:'{{fields.target}}'});">{{!action_folders_create}}</div>
		<div style="clear: both;"></div>
	</div>
	<div class="upload-many-block upload-block">
		<div class="field"><div class="name">{{!upload_downscale}}</div><div class="value"><input type="checkbox" name="downscale" class="downscale" value="1" checked="yes" onchange="$('.upload-many-block .maxsize').attr('disabled',!this.checked);uploader_init(uploader_post_params);"/></div></div>
		<div class="field"><div class="name">{{!upload_downscale_to}}</div>
			<div class="value">
				<input type="text" name="max_x" value="{{autoscale.x}}" class="ui-corner-all maxsize max-x" onkeyup="uploader_init(uploader_post_params);"/> x
				<input type="text" name="max_y" value="{{autoscale.y}}" class="ui-corner-all maxsize max-y" onkeyup="uploader_init(uploader_post_params);"/>
			</div>
		</div>
		<div class="swfupload-holder">
		</div>
	</div>
	<div class="upload-one-block upload-block">
		<form action="/admin-filebrowser__upload/" method="POST" enctype="multipart/form-data" target="upload-one-frame">
		<input type="hidden" name="ajaj" value="1"/>
		<input type="hidden" name="iframe" value="1"/>
		<input type="hidden" name="file_group_id" value="{{fields.file_group_id}}"/>
		<input type="hidden" name="file_type_id" value="{{fields.file_type_id}}"/>
		<input type="hidden" name="target" value="{{fields.target}}"/>
		<div class="field"><div class="name">{{!upload_one_field_file}}</div><div class="value"><input type="file" name="Filedata"/></div></div>
		<div class="field"><div class="name">{{!upload_one_field_name}}</div><div class="value"><input type="text" name="name" class="ui-corner-all iname"/></div></div>
		<div class="field"><div class="name">{{!upload_downscale}}</div><div class="value"><input type="checkbox" name="downscale" value="1" checked="yes" onchange="$('.upload-one-block .maxsize').attr('disabled',!this.checked);"/></div></div>
		<div class="field"><div class="name">{{!upload_downscale_to}}</div>
			<div class="value">
				<input type="text" name="max_x" value="{{autoscale.x}}" class="ui-corner-all maxsize"/> x
				<input type="text" name="max_y" value="{{autoscale.y}}" class="ui-corner-all maxsize"/>
			</div>
		</div>
		<div class="field"><div class="name">&nbsp;</div><div class="value"><input type="submit" value="{{!upload_one_field_submit}}" class="isubmit"/></div></div>
		</form>
		<iframe id="upload-one-frame" name="upload-one-frame" frameborder="0" width="1" height="1"></iframe>
	</div>
	{{if target_is_ajajform_file_group_id}}{{if fields.file_group_id}}
		<div><input id="button-use-this-folder" type="button" value="{{!button_use_this_folder}}"/></div>
		<script>$("#button-use-this-folder").button().bind("click",function() {document.location="{{action}}?mode=push_file_group_id&file_group_id={{fields.file_group_id}}";});</script>
	{{/if}}{{/if}}
	<div class="files">
	<form action="{{action}}" name="imgfrm" method="POST" onsubmit="ajaj_form(this);return false;">
	<input type="hidden" name="ajaj" value="1"/>
	<input type="hidden" name="mode" value="save_attrs"/>
	<input type="hidden" name="file_group_id" value="{{fields.file_group_id}}"/>
	<input type="hidden" name="file_type_id" value="{{fields.file_type_id}}"/>
	<input type="hidden" name="target" value="{{fields.target}}"/>
		{{foreach fg in current_file_groups}}
		<div class="folder">
			<a class="image" href="{{action}}?{{copy_fields("all,file_type_id,target")}}file_group_id={{fg.id}}"></a>
			<div onclick="filemanager_file_group_edit({parent_id: '{{fields.file_group_id}}',id: '{{fg.id}}', name: '{{JS:fg.name}}'},folders_tree,{file_type_id:'{{fields.file_type_id}}',file_group_id:'{{fields.file_group_id}}',target:'{{fields.target}}'});" class="name">{{fg.name}}</div>
		</div>
		{{/foreach}}
		<div style="clear: both;"></div>
		{{foreach f in files}}
		<div class="file">
			<div class="img-and-icons">
				<div class="img" id="img_{{f.id}}"><img src="{{f.image}}" border="0"/></div>
				<div class="icons">
					<a href="{{f.href}}" target="_blank"><img src="/shared/icons/web.png"/></a>
					<a href="{{action}}?mode=rotate_right&file_id={{f.id}}&ajaj=1" onclick="ajaj_href(this);return false"><img src="/shared/icons/rotate_ccw.png"/></a>
					<a href="{{action}}?mode=rotate_left&file_id={{f.id}}&ajaj=1" onclick="ajaj_href(this);return false"><img src="/shared/icons/rotate_cw.png"/></a>
				</div>
				<div class="cl"></div>
			</div>
			<div class="text" id="div-name-{{f.id}}">{{f.name}}</div>
		</div>
		{{/foreach}}
		<div style="clear: both;"></div>
		{{if can_delete}}<input type="submit" class="isubmit" value="{{!button_save_changed_filenames}}"/>{{/if}}
		{{if can_delete}}<input type="button" class="idelete" value="{{!button_delete_selected}}"/>{{/if}}
		{{if can_delete}}<input type="button" class="idelete_folder" value="{{!button_delete_folder}}"/>{{/if}}
	</div>
	</form>
</td></tr>
</table>
<script>
uploader_init(uploader_post_params);
$(".upload-one-block .field .value .isubmit").button();
$(".files .isubmit").button();
$(".files .idelete").button().bind("click",function() {
	var chkd=$(".files .file .checked");
	var str="";
	for (var i=0;i<chkd.length;i++) {
		if (str.length) str+=",";
		var arr=chkd[i].id.match(/(\d+)/);
		str+=arr[1];
	}
	var rt=$.ajax({type: "POST",url: "{{action}}",async: false,data: {file_ids: str,mode: "files_delete",ajaj: 1,file_group_id: "{{fields.file_group_id}}",file_type_id: "{{fields.file_type_id}}",target: '{{fields.target}}'} }).responseText;
    std_response(rt);
});
$(".files .idelete_folder").button().bind("click",function() {
	var a={{current_file_groups.length}}+{{files.length}};
	if (a) {
		alert("Folder is not empty");
	} else {
		if (confirm("Are you sure?")) {
			ajaj_href("/admin-filebrowser/?mode=file_group_delete&file_group_id={{fields.file_group_id}}&ajaj=1");
		}
	}
});
{{if can_check_images}}$(".files .file .img").bind("click",function() {$(this).toggleClass("checked");});{{/if}}
{{if target_is_tinymce}}$(".files .file .img").bind("click",function() {document.location="{{action}}?mode=popup_select&target={{fields.target}}&file_id="+this.id.match(/(\d+)/)[1];});{{/if}}
{{if target_is_ajajform_file_id}}
	$(".files .file .img").bind("click",function() {
		var file_id=this.id.match(/(\d+)/)[1];
		var url=$("img",this).attr("src").replace(/-preview\d\w*\./,".");
		var name=$("#div-name-"+file_id).text();
		parent.ajajform_file_id_set({
			id: file_id,
			name: name,
			url: url,
			file_group_id: '{{fields.file_group_id}}'
		});
	});
{{/if}}
{{if target_is_ajajform_urledit}}
	$(".files .file .img").bind("click",function() {
		var url=$("img",this).attr("src").replace(/-preview\d\w*\./,".");
		parent.ajajform_urledit_set(url);
	});
{{/if}}
{{if target_is_ajajform_gdbe}}
	$(".files .file .img").bind("click",function() {
		var url=$("img",this).attr("src").replace(/-preview\d\w*\./,".");
		parent.ajajform_gdbe_set(url);
	});
{{/if}}

$(".files .file .text").bind("click",function() {
	var t=$(this);
	var a=t.text();
	var arr=t.attr("id").match(/div-name-(\d+)/);
	$('<input type="text"/>').appendTo(t.empty()).attr("value",a).attr("name",arr[1]+"-name");
	t.unbind("click");
});
var folders_tree={{JSON:folders_tree}};
</script>
